﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using HuynhQuangWebsite.Models;
using THS.HtmlHelpers;
namespace HuynhQuangWebsite.Controllers
{
    public class Du_anController : BaseController
    {
        //
        // GET: /ProjectPage/
        huynhquangco_websiteEntities ctx = new huynhquangco_websiteEntities();
        public int PageSize = 6;
        public ActionResult Danh_sach(int page = 1)
        {
            var model = new HomeListViewModel();
            IList<Project> projects = ctx.Projects.Where(p=>p.ProjectIsVisible).ToList();
            model.ProjectList = projects.Skip((page-1) * PageSize).Take(PageSize).ToList();
            model.ProjectInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = projects.Count() };
          
            return View(model);
        }
        public ActionResult Paging(int page = 1)
        {
            var model = new HomeListViewModel();
            IList<Project> projects = ctx.Projects.Where(p => p.ProjectIsVisible).ToList();
            model.ProjectList = projects.Skip((page-1) * PageSize).Take(PageSize).ToList();
            model.ProjectInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = projects.Count() };
            return PartialView("UCProjectList", model);
        }
        public ActionResult Chi_tiet(int id)
        {
           
            var model = new DetailsListViewModel();
            Project project = ctx.Projects.Where(p => p.ProjectID == id).SingleOrDefault();
            model.CurrentProject = project;
            model.FlagID = project.ProjectID;
            //get top recent project
            IList<Project> projectList = ctx.Projects.OrderByDescending(p => p.ProjectStartDate).Take(5).ToList();
            model.ProjectList = projectList;
            return View(model);
        }
    }
}
